package com.baijing.springbootstartermonitor.utils;

import com.baijing.springbootstartermonitor.service.StatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

/**
 * 自定义HealthIndicator
 * http://127.0.0.1:8080/health
 */
@Component
public class StatusHealth implements HealthIndicator {
    @Autowired
    private StatusService statusService;

    @Override
    public Health health() {
        String status = statusService.getStatus();
        if (status == null || !status.equals("running")) {
            return Health.down().withDetail("Error", "Not Running").build();
        }
        return Health.up().build();
    }
}
